// pages/my-team/my-team.js
const SERVICE = require("../../service.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let openid = wx.getStorageSync("token"); 
    console.log(JSON.parse(options.list));   
    this.setData({
      drpId: options.drpId,
      list: JSON.parse(options.list).son,
      dataSample: JSON.parse(options.list).son
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  month(){
    let td = this.data;
    let openid = wx.getStorageSync("token");
    
    this.setData({
      status: !td.status
    });
  },
  changeSearch(e){
    let td = this.data,val = e.detail.val;
    if (isNaN(parseFloat(val))){
      this.setData({
        list: searchName(td.dataSample, val)
      });
    }else{
      console.log("number",val);
      this.setData({
        list: searchMobile(td.dataSample, val)
      });
    }
  },
  detail(e){    
    let td = this.data,
    index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '../my-team-detail/my-team-detail?detailData=' + JSON.stringify(td.list[index]),
    })

  }
})

function getMyTeam(e,params){
  wx.showNavigationBarLoading();
  SERVICE.getMyTeam(params,(status,data)=>{
    wx.hideNavigationBarLoading();
    console.log("我的团队数据:",data);
    e.setData({
      dataSample: data.data,
      list:data.data
    });
  });
}


function searchName(data,val){
  let arry = [];
  for(let i = 0;i < data.length; i++){
    if (data[i].real_name.indexOf(val) != -1){
      console.log(i);
      arry.push(data[i]);
    }
  }
  return arry
}

function searchMobile(data,val){
  let arry = [];
  for (let i = 0; i < data.length; i++) {
    console.log(data[i].shop_mobile);
    if (data[i].shop_mobile.indexOf(val) != -1) {
      console.log(i);
      arry.push(data[i]);
    }
  }
  return arry
}